package test.y2020;

import cn.hutool.core.lang.Console;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author song
 * @date 2020/3/19 10:58
 */
public class March4 {
    public static void main(String[] args) {


        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();

        Console.error(key);
        Console.error(key.length);


        String content = "{\"code\":0,\"msg\":\"success\",\"message\":\"success\",\"ts\":1584587295869,\"data\":{\"msg\":\"解密成功！\",\"code\":0,\"userInfoMobile\":null,\"userInfoDetail\":{\"openId\":\"oB0WL5fMf63DL70-xROKz1QXWlXU\",\"nickName\":\"千里之行 始于足下\",\"gender\":\"1\",\"city\":\"Chengdu\",\"province\":\"Sichuan\",\"country\":\"China\",\"avatarUrl\":\"https://wx.qlogo.cn/mmopen/vi_32/kTZ9SjUmiaFE3DFl1h7PS4UqhzmgAHAb7SdDkZDugmEAze8fNbHf5NRAuEFbLWktyefzhzU07CHGJFnDgQ2WeibQ/132\",\"unionId\":\"oWHm60nO7f12ih0lwTLKRRDk4bm8\"}},\"success\":true}";

        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);

        byte[] encrypt = aes.encrypt(content);
        byte[] decrypt = aes.decrypt(encrypt);

        Console.error(encrypt);
        Console.error(decrypt);

        String encryptHex = aes.encryptHex(content);
        String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);

        Console.error(encryptHex);
        Console.error(decryptStr);
    }
}
